﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Manon.Repository.Extensions
{
    public class ReposUser : IReposUser
    {
        public ReposUser(IHttpContextAccessor accessor)
        {
            if (accessor != null
                && accessor.HttpContext != null
                && accessor.HttpContext.Request != null
                && accessor.HttpContext.Request.Headers != null)
            {
                string userId = accessor.HttpContext.Request.Headers["UserId"];
                if (!string.IsNullOrEmpty(userId))
                {
                    this.UserId = int.Parse(userId);
                } 

                string userType = accessor.HttpContext.Request.Headers["UserType"];
                if (!string.IsNullOrEmpty(userType))
                {
                    this.UserType = int.Parse(userType);
                }
                string tenantId = accessor.HttpContext.Request.Headers["TenantId"];
                if (!string.IsNullOrEmpty(tenantId))
                {
                    this.TenantId = int.Parse(tenantId);
                }
                return;
            }
            this.UserId = 0; 
        }
         
    }
}
